﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace _00365.Configurations
{
	public partial class ManageRoles : System.Web.UI.Page
	{
		protected void Page_Load(object sender, EventArgs e)
		{
			if (!IsPostBack)
			{
				loadRolesData();
			}
		}
		protected void loadRolesData()
		{
			grdRoles.DataSource = Biz.UserGroups.GetAll();
			grdRoles.DataBind();
		}
		protected void grdRoles_RowCommand(object sender, GridViewCommandEventArgs e)
		{
			Data.UserGroup role = null;
			switch (e.CommandName)
			{
				case "EditRow":
					Response.Redirect(ResolveClientUrl("~/Configurations/EditRoles.aspx?id=" + e.CommandArgument));
					break;

				case "DeleteRow":
					if (e.CommandName != string.Empty && e.CommandArgument.ToString().Length == 36)
						role = Biz.UserGroups.Get(new Guid(e.CommandArgument.ToString()));
					if (role != null) {
						Biz.UserGroups.Remove(role.Id);
						loadRolesData();
					}
					break;
			}
		}
	}
}